package com.wchen.nio.capter2_2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * @作者： wchen
 * @描述：
 * @创建时间： 2018/7/30 20:48
 * @版本：Copyright 2018, Inc. All Rights Reserved.
 * @修改信息：
 */
public class TimeClient {


    public static void main(String[] args) {
        int port = 2005;
        String host = "127.0.0.1";
        Socket socket = null;
        BufferedReader bufferedReader = null;
        PrintWriter printWriter = null;

        try {
            socket = new Socket(host, port);
            bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));

            printWriter = new PrintWriter(socket.getOutputStream(), true);
            printWriter.println("QUERY TIME ORDER");

            System.out.println("Send order 2 server succeed.");
            String resp = bufferedReader.readLine();
            System.out.println("Now is :" + resp);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if(printWriter != null){
                printWriter.close();
            }
            if(bufferedReader != null){
                try {
                    bufferedReader.close();
                }catch (IOException e1){
                    e1.printStackTrace();
                }
            }
            bufferedReader = null;
            if(socket != null){
                try {
                    socket.close();
                }catch (IOException e1){
                    e1.printStackTrace();
                }
            }
            socket = null;
        }
    }
}
